from django import forms
from .models import Warehouse,Good_category

class WarehouseForm(forms.ModelForm):
    class Meta:
        model = Warehouse
        # fields = ['name',]
        fields = '__all__'

        labels = {'name':'仓库名称',
                }
    def clean_name(self):
        name=self.cleaned_data.get('name')
        if Warehouse.objects.filter(name=name).exists():
            raise forms.ValidationError('仓库已经存在')
        return name
class WarehouseForm(forms.ModelForm):
    class Meta:
        model = Warehouse
        # fields = ['name',]
        fields = '__all__'

        labels = {'name':'仓库名称',
                }
    def clean_name(self):
        name=self.cleaned_data.get('name')
        if Warehouse.objects.filter(name=name).exists():
            raise forms.ValidationError('仓库已经存在')
        return name
class WarehouseForm(forms.ModelForm):
    class Meta:
        model = Warehouse
        # fields = ['name',]
        fields = '__all__'

        labels = {'name':'仓库名称',
                }
    def clean_name(self):
        name=self.cleaned_data.get('name')
        name=name.strip()
        if Warehouse.objects.filter(name=name).exists():
            raise forms.ValidationError('仓库已经存在')
        return name


class GoodCategoryForm(forms.ModelForm):
    class Meta:
        modle = Good_category
        field = {
            'name':'分类名称',
            'description':'分类描述'
        }
    def clean_name(self):
        name=self.cleaned_data.get('name')
        name=name.strip()
        if Good_category.objects.filter(name=name).exists():
            raise forms.ValidationError('分类已经存在')
        return name
